home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / sspell14.zip / STOP.C < prev    next >
C/C++ Source or Header  |  1992-07-18  |  5KB  |  140 lines

  1. /* **************************************************************** */
  2. /*             sspell - similar to Unix spell                       */
  3. /*                        version 1.4                               */
  4. /*                                                                  */
  5. /* Author: Maurice Castro                                           */
  6. /* Release Date:  4 Jul 1992                                         */
  7. /* Bug Reports: maurice@bruce.cs.monash.edu.au                      */
  8. /*                                                                  */
  9. /* This code has been placed by the Author into the Public Domain.  */
  10. /* The code is NOT covered by any warranty, the user of the code is */
  11. /* solely responsible for determining the fitness of the program    */
  12. /* for their purpose. No liability is accepted by the author for    */
  13. /* the direct or indirect losses incurred through the use of this   */
  14. /* program.                                                         */
  15. /*                                                                  */
  16. /* Segments of this code may be used for any purpose that the user  */
  17. /* deems appropriate. It would be polite to acknowledge the source  */
  18. /* of the code. If you modify the code and redistribute it please   */
  19. /* include a message indicating your changes and how users may      */
  20. /* contact you for support.                                         */
  21. /*                                                                  */
  22. /* The author reserves the right to issue the official version of   */
  23. /* this program. If you have useful suggestions or changes for the  */
  24. /* code, please forward them to the author so that they might be    */
  25. /* incorporated into the official version                           */
  26. /*                                                                  */
  27. /* Please forward bug reports to the author via Internet.           */
  28. /*                                                                  */
  29. /* Contributors: mao@physics.su.oz.au                               */
  30. /*                                                                  */
  31. /* **************************************************************** */
  32.  
  33. /* This set of routines provides the stop list */
  34.  
  35. /* The stop list implementation is grossly inefficient, however, the  */
  36. /* stop list should be very short so the time penalty should be small */
  37. /* in comparison to the processing time. If the stop list gets large  */
  38. /* then the rules are wrong or inefficient. It is recommended that    */
  39. /* the offending rules producing the large number of wrong results be */
  40. /* removed and the correct words provided by the rule be added to the */
  41. /* dictionary                                                         */
  42.  
  43. #include <stdio.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46. #if !defined(pyr)
  47. #include <stdlib.h>
  48. #endif
  49. #include "error.h"
  50. #include "config.h"
  51. #include "stop.h"
  52. #include "strfn.h"
  53.  
  54. typedef struct liststr
  55. {
  56.    char *name;
  57.    struct liststr *next;
  58.    } LIST;
  59.  
  60. static int maxcachesize;
  61. static LIST *list;
  62.  
  63. static void memfail()
  64. {
  65.    errormesg("Error: Out of Memory! Terminating",-3);
  66.    }
  67.  
  68. void initstop(stop)
  69. char *stop;
  70. {
  71.     FILE *f;
  72.     char instr[MAXSTR];
  73.     LIST *cur;
  74.     char *c;
  75.     int i;
  76.  
  77.     f = fopen(stop,"rt");
  78.     if (f == NULL)
  79.         return;
  80.  
  81.     i = 0;
  82.     if (fgets(instr, MAXSTR, f) == NULL)
  83.         return;
  84.     c = strrchr(instr,'\n');
  85.     if (c != NULL)
  86.         *c = NULL;
  87.  
  88.     list = (LIST *) malloc(sizeof(LIST));
  89.     if (list == NULL) 
  90.         memfail();
  91.     list->name = (char *) malloc(strlen(instr)+1);
  92.     if (list->name == NULL) 
  93.         memfail();
  94.     strcpy(list->name, instr);
  95.     list->next = NULL;
  96.  
  97.     cur = list;
  98.     
  99.     while (!feof(f))
  100.     {              
  101.         if (fgets(instr, MAXSTR, f) == NULL)
  102.             break;
  103.         c = strrchr(instr,'\n');
  104.         if (c != NULL)
  105.             *c = NULL;
  106.         cur->next = (LIST *) malloc(sizeof(LIST));
  107.         if (cur->next == NULL)
  108.             memfail();
  109.         cur = cur->next;
  110.         cur->name = (char *) malloc(strlen(instr)+1);
  111.         if (cur->name == NULL)
  112.             memfail();
  113.         strcpy(cur->name, instr);
  114.         cur->next = NULL;
  115.         i++;
  116.         if (i > MAXSTOP)
  117.         {
  118.             fprintf(stderr, "Warning: Stop list file too large\n");
  119.             fprintf(stderr, "Ignoring entries beyond: %s\n", instr);
  120.             fprintf(stderr, "Revise rule file and edit stop list\n");
  121.             break;
  122.             }
  123.         }
  124.     fclose(f);
  125.     }
  126.  
  127. int instop(s)
  128. char *s;
  129. {
  130.     LIST *cur;
  131.     cur = list;
  132.     while (cur != NULL)
  133.     {
  134.         if (!strcmp(cur->name, s))
  135.             return(1);
  136.         cur = cur->next;
  137.         }
  138.     return(0);
  139.     }
  140.